package components;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

import uml.Visitable;
import uml.Visitor;

public class Class implements Visitable {
	private String name;
	private String accessQualifier;
	private String _abstract;
	private String _static;
	private String _final;
	private String _extends;
	private String interfaces;	
	private String superClass;	
	private boolean _interface = false;	
	private boolean _enum = false;
	private String packageName;
	
	//poziom zagniezdzenia klasy
	private int level;
	
	private HashMap<String,Field> fields = new HashMap<String,Field>();
	private HashMap<String, Method> methods = new HashMap<String,Method>();
	private HashMap<String, Class> innerClasses = new HashMap<String,Class>();	
	
	public Class(){}
	
	public void setInterfaces(String interfaces){
		this.interfaces = interfaces;
	}
	
	public String getStatic() {
		return _static;
	}

	public void setStatic(String _static) {
		this._static = _static;
	}

	public String getFinal() {
		return _final;
	}

	public void setFinal(String _final) {
		this._final = _final;
	}

	public boolean isInterface() {
		return _interface;
	}

	public void setInterface(boolean _interface) {
		this._interface = _interface;
	}

	
	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public Class(String name){
		this.name = name;
	}
	
	public ArrayList<Class> getInnerClasses() {
		ArrayList<Class> ret = new ArrayList<Class>();
		
		for(String s : innerClasses.keySet()){
			ret.add(innerClasses.get(s));
		}
		
		return ret;
	}
	
	public void setInnerClasses(HashMap<String, Class> innerClasses) {
		this.innerClasses = innerClasses;
	}
	
	public void addInnerClass(Class _class){
		innerClasses.put(_class.toString(), _class);
	}
	
	public String getExtends() {
		return _extends;
	}

	public void setExtends(String _extends) {
		this._extends = _extends;
	}
	
	public String getAccessQualifier() {
		return accessQualifier;
	}

	public void setAccessQualifier(String accessQualifier) {
		this.accessQualifier = accessQualifier;
	}

	public String getAbstract() {
		return _abstract;
	}

	public void setAbstract(String _abstract) {
		this._abstract = _abstract;
	}
	
	public String getSuperClass() {
		return superClass;
	}

	public void setSuperClass(String superClass) {
		this.superClass = superClass;
	}

	public String getName(){
		return name;
	}
	
	public void setName(String name){
		this.name = name;
	}
	
	public void addField(Field field){
		fields.put(field.toString(), field);		
	}
	
	public void addMethod(Method method){
		methods.put(method.toString(), method);		
	}
	
	public HashMap<String,Field> getFields(){
		return fields;
	}
	
	public HashMap<String,Method> getMethods(){
		return methods;
	}
		
	public Field getField(String name){
		return fields.get(name);
	}
	
	public Method getMethod(String name){
		return methods.get(name);
	}
	
	public boolean isEnum() {
		return _enum;
	}

	public void setEnum(boolean _enum) {
		this._enum = _enum;
	}	
	
	public String toString(){

		if(isEnum())
			return "enum " + accessQualifier + " " + _static + " " + _final + " " + _abstract + " " + " " +name + " extends " + _extends + " implements " + interfaces;
		if(isInterface())
			return "interface " + accessQualifier + " " + _static + " " + _final + " " + _abstract + " " + " " +name + " extends " + _extends;
		
		return "class " + accessQualifier + " " + _static + " " + _final + " " + _abstract + " " + " " +name + " extends " + _extends + " implements " + interfaces;
	}

	@Override
	public void accept(Visitor visitor) {
		visitor.visit(this);
	}

	public void setPackageName(String packageName) {
		this.packageName = packageName;
	}

	public String getPackageName() {
		return packageName;
	}

	public String getInterfaces() {
		return interfaces;
	}
}
